<template>
	<view class="">

		<cu-custom bgColor="bg-white" :isBack="true" :isTitle="false">
			<block slot="backText" class="titilestyle">{{title}}</block>

		</cu-custom>
		<Loading class="loading-box" v-show="!isLoading" :isStatus='loadStatus'></Loading>

		<scroll-view scroll-y="true" :style="{height: swiperHeight+'px'}">
			<view class="">
				<view class="oi-detail">
					<view class="oi-header">
						<view class="oi-order-status">
							<view>
								<text v-if="orderInfo.order_status==0 && orderInfo.pay_status==0" class="red-color">待支付
									<text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==0 && orderInfo.pay_status==1"
									class="blue-color">等待商家接单 <text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==4">订单完成 <text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==3">订单取消 <text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==1" class="blue-color">正在出餐中 <text
										class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==2 && orderInfo.shipping_status==0"
									class="blue-color">等待骑手取餐 <text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==2 && orderInfo.shipping_status==1"
									class="blue-color">骑手配送中 <text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==5">商家已拒绝接单 <text class="cuIcon-right"></text></text>
								<text v-if="orderInfo.order_status==6" class="red-color">退款处理中 <text
										class="cuIcon-right"></text></text>
							</view>
							<view>
								<text v-if="orderInfo.is_downstairs==1" style="margin-right: 20upx;">送到楼下</text>
								<text v-if="orderInfo.is_reserve==1">预定</text>
								<text v-if="orderInfo.take_self==1">自取</text>
								<text v-if="orderInfo.take_self==0">外送</text>

							</view>
						</view>
						<view class="oi-thank">
							<!-- 2021 05 11 xh 修改订单信息 -->
							<text v-if="orderInfo.cancel_desc==null">感谢您的信任，期待再次光临</text>
							<text v-html="orderInfo.cancel_desc" v-if="orderInfo.cancel_desc!=null"></text>

						</view>
						<view class="oi-order-btn">
							<text class="order-btn" v-if="orderInfo.order_status==0"
								@click="cancelOrder(orderInfo.order_id)">取消订单</text>
							<text class="order-btn order-btn-blue"
								v-if="orderInfo.order_status==0 && orderInfo.pay_status==0"
								@click="pay(orderInfo.order_id)">立即支付</text>
							<text class="order-btn" v-if="orderInfo.order_status==2"
								@click="confirmOrder(orderInfo.order_id)">确认收货</text>
							<text class="order-btn order-btn-blue"
								v-if="orderInfo.order_status==4 && orderInfo.commentNum==0"
								@click="comment(orderInfo.order_id)">立即评价</text>
							<text class="order-btn" @click="buyagain">再来一单</text>
							<text class="order-btn" v-if="orderInfo.order_status==4"
								@click="aftersale(orderInfo.order_id)">申请售后</text>
						</view>
					</view>
					<view class="oi-deliver">
						<view v-if="orderInfo.horseman_id == 0 && orderInfo.delivery_self==0"><text>等待骑手接单</text></view>
						<view class="horseInfo" v-if="orderInfo.horseman_id > 0">
							<text>	{{orderInfo.horseman_relay?orderInfo.horseman_relay.realname:orderInfo.horseman.realname}}
							</text><text class="ps-ico">配送</text><text v-if="orderInfo.delivery_self>0"
								class="deliveryMer">该订单由商家自主配送</text>
							<view class="notice">长时间未收到，可联系配送员哦~</view>
						</view>
						<view class="call"
							@click="call(orderInfo.horseman_relay?orderInfo.horseman_relay.mobile:orderInfo.horseman.mobile)"
							v-if="orderInfo.horseman_id > 0">
							<text class="cuIcon-phone"></text>
						</view>
					</view>

					<view class="oi-goods">
						<view class="oi-shop-info" v-if="orderInfo.shopInfo.logo">
							<image mode="aspectFill" :src="orderInfo.shopInfo.logo" class="oi-shop-logo"
								@error="errorLogo"></image>
							<view class="oi-shop-title"><text>{{orderInfo.shopInfo.shop_name}}</text></view>
						</view>
						<view class="line-gray" v-if="shopInfo.logo">

						</view>

						<view class="oi-fee-item">
							<text class="tit">文件页数</text>
							<text>{{orderInfo.num}}页</text>
						</view>
						<view class="oi-fee-item">
							<text class="tit">单页价格</text>
							<text>{{orderInfo.goodsInfo.price || 0}}元/页</text>
						</view>
						<view class="oi-fee-item">
							<text class="tit">打印份数</text>
							<view class="fr  water-item-right">
								{{orderInfo.copies}}份

							</view>
						</view>

						<view class="line-gray">

						</view>

						<view class="oi-fee-item">
							<text class="tit-style ">实付款</text>
							<view class="">

								<text class="total-price tit-style">￥{{orderInfo.online_amount || 0.00}}</text>
							</view>
						</view>


					</view>

			

					<view class="oi-orther-detail ">
						<view class="oi-orther-item ">
							<text class="oi-tit ">期望时间：</text>
							<text class="gray-color " v-if="orderInfo.reserve_time">{{orderInfo.reserve_time}}</text>
							<text class="gray-color " v-else>立即配送</text>
						</view>
						<view class="oi-orther-item">
							<text class="oi-tit">支付方式：</text>
							<text class="gray-color" v-if="orderInfo.pay_code =='wxpay'">微信</text>
							<text class="gray-color" v-if="orderInfo.pay_code =='wxgzh'">微信</text>
							<text class="gray-color" v-if="orderInfo.pay_code =='wxpayApp'">微信</text>
							<text class="gray-color" v-if="orderInfo.pay_code =='alipay'">支付宝</text>
							<text class="gray-color" v-if="orderInfo.pay_code =='other'">其他</text>
						</view>
						<view class="oi-orther-item">
							<text class="oi-tit ">配送地址：</text>
							<view>
								<view><text
										class="gray-color">{{orderInfo.consignee || '--'}},{{orderInfo.mobile || '--'}}
									</text></view>
								<view><text class="gray-color">{{orderInfo.address || '--'}}</text></view>
							</view>
						</view>
						<view class="oi-orther-item">
							<text class="oi-tit">订单编号：</text>
							<text class="gray-color oi-order-text"
								style="letter-spacing:5rpx">{{orderInfo.order_sn}}</text>
						</view>
						<view class="oi-orther-item">
							<text class="oi-tit">订单时间：</text>
							<text class="gray-color oi-order-text">{{orderInfo.created_at || '--'}}</text>
						</view>

						<view class="oi-orther-item" v-if="orderInfo.user_note">
							<text class="oi-tit">备注：</text>
							<text class="gray-color oi-order-text">{{orderInfo.user_note || '--'}}</text>
						</view>
					</view>
				</view>
			</view>



			<view class="foot">

			</view>
		</scroll-view>
	</view>


</template>

<script>
	export default {

		data() {
			return {
				isLoading: false, //是否加载完成显示
				loadStatus: 'load',
				title: "订单详情",
				order_id: 0,
				StatusBar: this.Custom,
				orderInfo: {
					shop: {},
					order_bill: {}
				},
				cartInfo: {},
				cartList: {},
				cartGoodsNum: {},
				goodsList: {},
				timeID: 0,
				swiperHeight: '0px',
			}
		},
		onLoad(option) {
			this.order_id = option.order_id
			this.getOrder()
		},
		onShow(option) {

		},
		onHide(e) {
			// clearInterval(this.timeID)
		},
		onPullDownRefresh() {
			this.getOrder()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		mounted() {
			this.getInfo().then((e) => {

				this.swiperHeight = e.screenHeight - (e.custom.top + e.custom.height);

			});

		},
		methods: {
			errorImg(index) { //图片加载失败给出默认图
				this.orderInfo.order_goods[index].thumb = this.resDomain + "/static/img/error.png";
				this.$set(this.orderInfo.order_goods, index, this.orderInfo.order_goods[index]);
			},
			errorLogo() {
				this.$nextTick(() => {
					this.orderInfo.shop.logo = this.resDomain + "/static/img/error.png";
				})
			},
			getOrder() {
				this.apiRequest('/buyer/pOrderInfo', {
					order_id: this.order_id
				}, '', 'get').then(res => {

					this.orderInfo = res.data;
					this.isLoading = true;

				})
			},
			call(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				});
			},
			cancelOrder(order_id) {
				this.apiRequest('/buyer/pOrdercancel', {
					order_id: order_id
				}).then(res => {
					if (res.code == 200) {
						this.getOrder()
					}
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				})
			},
			confirmOrder(order_id) {
				this.apiRequest('/buyer/OrderConfirm', {
					order_id: order_id
				}).then(res => {
					if (res.code == 200) {
						this.getOrder(this.order_id)
					}
					uni.showToast({
						title: res.msg
					})
				})
			},
			aftersale(order_id) {
				uni.navigateTo({
					url: '/app/TakeOut/pages/user/afterSale?order_id=' + order_id
				});
			},
			comment(order_id) {
				uni.navigateTo({
					url: '/app/TakeOut/pages/user/commentOrder?order_id=' + order_id
				});
			},
			pay(order_id) {
				uni.navigateTo({
					url: '/app/CloudPrint/pages/order/pay?order_id=' + order_id
				});
			},
			copyData(data) {
				uni.setClipboardData({
					data: data,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				});
			},
			buyagain() {

				uni.redirectTo({
					url: '/app/CloudPrint/pages/index/index'
				});

			}

		}
	}
</script>

<style scoped>
	view {
		line-height: 1.8;
	}

	.oi-detail {
		width: 94%;
		margin-left: 3%;
		height: 100%;
		margin-top: 10upx;
	}

	.line-gray {
		width: 100%;
		height: 2upx;
		background-color: #EEEEEE;
		opacity: 0.4;
		margin: 20upx 0 20upx 0;
	}

	.use-style {
		font-size: 24upx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-right: 10upx;
	}

	.oi-header,
	.oi-deliver,
	.oi-goods,
	.oi-fee,
	.oi-total,
	.oi-orther-detail {
		background: #FFFFFF;
		padding: 30rpx 5%;
		margin-bottom: 15rpx;
		border-radius: 20rpx;

	}

	.oi-header .oi-order-status {
		font-size: 32rpx;
		font-weight: bold;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.oi-header .oi-thank {
		color: #666666;
		font-size: 24rpx;
	}

	.oi-thank {
		padding: 5upx 0 5upx 0;
	}

	.oi-header .oi-order-btn {
		margin-top: 15rpx;
	}

	.oi-header .oi-order-btn text {
		padding: 10rpx 20rpx;
		margin-right: 15rpx;
		border-radius: 20rpx;
		border: solid 1px #dbdbdb;
		font-size: 28rpx;
		color: #999999;
	}

	.oi-header .oi-order-btn .order-btn-blue {
		background-color: #3589f7;
		color: #FFFFFF;
		border-radius: 20rpx;
	}

	.oi-deliver {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.oi-deliver .horseInfo .notice {
		color: #1270e0;
		font-size: 18rpx;
	}

	.oi-deliver .horseInfo .ps-ico {
		font-size: 20rpx;
		margin-left: 10rpx;
	}

	.oi-shop-info {
		display: flex;
		align-items: center;
	}

	.oi-deliver .call,
	.oi-shop-info .call {
		margin-left: auto;
	}

	.oi-goods .oi-shop-info {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.oi-goods .oi-shop-info .oi-shop-logo {
		width: 45rpx;
		height: 45rpx;
		border-radius: 50%;
	}

	.oi-goods .oi-shop-info .oi-shop-title {
		margin-left: 10rpx;
		font-weight: bold;
		font-size: 32upx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.oi-goods-list {
		margin-top: 40rpx;
	}

	.oi-goods-item {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		margin-bottom: 15rpx;
	}

	.oi-goods-item view {
		line-height: 1.4;
	}

	.oi-goods-item .goodsThumb {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}

	.oi-goods-item .goods-detail {
		margin-left: 10rpx;
		width: 65%;
	}

	.oi-goods-item .goods-detail .goodsName {
		width: 100%;
		font-weight: bold;
	}

	.oi-goods-item .goods-detail .goodsSpec text {
		font-size: 20rpx;
		margin-right: 15rpx;
		color: #666666;
	}

	.oi-goods-item .goods-detail .goodsNum {
		font-size: 20rpx;
		margin-top: 10rpx;
	}

	.oi-goods-item .goods-price {
		margin-left: auto;
		width: 15%;
		text-align: right;
	}

	.oi-goods-item .goods-price .markprice {
		font-size: 24rpx;
		margin-top: 15rpx;
		text-decoration: line-through;
		color: #666666;
	}

	.oi-fee-item {
		min-height: 80upx;
		align-items: center;
	}

	.oi-fee-item,
	.oi-orther-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding-bottom: 10rpx;
		font-size: 28rpx;
		width: 100%;
	}

	.oi-fee-item .minusfee {
		color: #FF3333;
	}

	.oi-total {
		text-align: right;
	}

	.oi-tit {

		white-space: nowrap;
	}

	.oi-total .total-prom {
		color: #666666;
		font-size: 24rpx;
	}

	.oi-total .total-price {
		font-weight: bold;
		margin-left: 10rpx;
	}

	.oi-orther-item {
		display: flex;
		min-height: 80upx;
		justify-content: space-between;
	}

	.oi-orther-item view {
		text-align: right;
	}

	.oi-orther-item .tit {
		color: #666666;
		width: 20%;
	}

	.oi-orther-item .copy-btn {
		margin-left: auto;
	}

	.tit-box {
		padding: 5rpx 15rpx 5rpx 15rpx;
		background: #FFF0F0;
		border: 2upx solid #F4D5D5;
		border-radius: 10upx;
	}

	.tit-style {
		font-size: 32upx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.oi-order-text {
		word-wrap: break-all;
		word-break: break-word;
		text-align: right;
	}

	.cuIcon-phone {
		color: #000000;
		font-size: 48rpx;
	}
</style>
